import { createMemoryHistory, createRouter } from 'vue-router'

import ConfigView from '../view/config/config.vue'
import SystemView from '../view/system/system.vue'
import DashboardView from '../view/dashboard/dashboard.vue'

import NProgress from '../config/nprogress'


const routes = [
    {
        path: '/config',
        name: "config",
        meta:{name:"配置中心"},
        component: ConfigView
    },

    {
        path: '/system',
        name: "system",
        meta:{name:"资金流向"},
        component: SystemView
    },

    {
        path: '/dashboard',
        name: "dashboard",
        meta:{name:"股票"},
        component: DashboardView
    },
]

const router = createRouter({
    history: createMemoryHistory(),
    routes,
})

router.beforeEach(async (to, from, next) => {

    // 1.NProgress 开始
    NProgress.start();

    next();
});

router.onError(error => {
    NProgress.done();
    console.warn("路由错误", error.message);
});

/**
 * @description 路由跳转结束
 * */
router.afterEach(() => {
    NProgress.done();
});

export default router